package observer1;

import java.util.Observable;
import java.util.Observer;

import observer0.Displayment;

/**
 * @author Frank
 * @create 2018-11-16 17:15
 * @desc 描述
 **/
public class CurrentConditionDisplay implements Observer, Displayment {

    Observable observable;
    private float temperature;
    private float humidity;

    public CurrentConditionDisplay(Observable observables) {
        this.observable = observables;
        observable.addObserver(this);
    }


    @Override
    public void update(Observable o, Object arg) {
        if (o instanceof WeatherData) {
            WeatherData weatherData = (WeatherData) o;
            this.temperature = weatherData.getTemp();
            this.humidity = weatherData.getHumid();
            display();
        }
    }

    @Override
    public void display() {
        System.out.println("CurrentConditionDisplay  {" +
            ", temperature=" + temperature +
            ", humidity=" + humidity +
            '}');
    }
}
